﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.Authorization.API.Application.Command.Role;
using S.Authorization.API.Application.Command.RoleMenuCommand;
using S.Authorization.Common.RabbitMQ;
using S.Authorization.Domain.Model.Authority;

namespace S.Authorization.API.Controllers
{
    /// <summary>
    /// 角色和菜单--写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RoleMenuController : ControllerBase
    {
        #region 注入
        private readonly IMediator mediator;
        

        public RoleMenuController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        #endregion

        /// <summary>
        /// 设置用户的角色权限
        /// </summary>
        /// <param name="command">添加的数据</param>
        /// <returns>返回受影响的行数</returns>
        [HttpPost]
        public async Task<int> AddRangeRoleMenu(RoleMenuAddRangeCommand command)
        {
            return await mediator.Send(command);
        }
        /// <summary>
        /// 角色表添加
        /// </summary>
        /// <param name="command">添加的数据</param>
        /// <returns>返回受影响的行数是否大于0</returns>
        [HttpPost]
        public async Task<bool> AddRoleAsync(RoleAddCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 角色表删除
        /// </summary>
        /// <param name="roleId">角色Id</param>
        /// <returns>返回受影响的行数是否大于0</returns>
        [HttpDelete]
        public async Task<bool> DeleteRoleAsync(int roleId)
        {
            return await mediator.Send(new RoleDeleteCommand()
            {
                RoleId = roleId
            });
        }


        /// <summary>
        /// 角色表修改
        /// </summary>
        /// <param name="command">修改的数据</param>
        /// <returns>返回受影响的行数是否大于0</returns>
        [HttpPut]
        public async Task<bool> UpdateRoleAsync(RoleUpdateCommand command)
        {
            return await mediator.Send(command);
        }

        /// <summary>
        /// 删除菜单功能角色表
        /// </summary>
        /// <param name="menuId">菜单ID</param>
        /// <param name="roleId">角色ID</param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<bool> DeleteRangeFeatureMenuRole(string menuId, string roleId)
        {
            return await mediator.Send(new FeatureMenuRoleDeleteRangeCommand()
            {
                MenuId = menuId,
                RoleId = roleId
            });
        }
        


    }
}
